package com.glory.gloryquickui.activity

import android.os.Bundle
import android.view.View
import com.glory.gloryquickui.R
import com.glory.gloryquickui.base.BaseActivity
import com.glory.gloryquickui.utils.InitUtils
import com.glory.gloryquickui.viewmodel.LoginViewModel
import com.glory.gloryquickui.viewmodel.SettingViewModel
import kotlinx.android.synthetic.main.activity_setting.*

/**
 * FileName: SettingActivity
 * Author: XJH
 * Date: 2021/6/2 10:48
 * Description:
 * History:
 */
class SettingActivity : BaseActivity<SettingViewModel>(), View.OnClickListener {
    override fun layoutId(): Int {
        return R.layout.activity_setting
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle("设置")
        viewModel.initVersion(this)
        tvIP.text = InitUtils.BaseUrl
        tvFileIP.text = InitUtils.FileUrl
        rlIP.setOnClickListener(this)
        rlFileIP.setOnClickListener(this)
    }

    override fun initData() {
        viewModel.defUI.callObserve.observe(this){
            when(it.type){
                0 -> tvVersion.text = it.item as String
                1 -> tvIP.text = it.item as String
                2 -> tvFileIP.text = it.item as String
            }
        }
    }

    override fun onClick(p0: View?) {
        when(p0?.id){
            R.id.rlIP -> viewModel.showScanDialog(this,1)
            R.id.rlFileIP -> viewModel.showScanDialog(this,2)
        }
    }
}